//
// Created by User on 24-10-3.
//
#include <gtest/gtest.h>
#include <glog/logging.h>
#include <libavcodec/packet.h>

#include "general_demuxer.h"
#include "demuxer_error.hpp"
TEST(demuxer_test, demuxer_init)
{
    demuxer::general_demuxer gd1(VIDEO_PATH);

    ASSERT_THROW(
        {
        demuxer::general_demuxer gd2("./");
        }, error::demuxer_error);
}


TEST(demuxer_test, demuxer_get_video_pkt)
{
    demuxer::general_demuxer gd1(VIDEO_PATH);
    auto& video_stream = gd1.get_streams().front();
    for (int cnt = 1;; ++cnt)
    {
        auto pkt = video_stream->get_packet();
        if (!pkt)
        {
            break;
        }
        LOG(INFO) << cnt << "\tpts : " << pkt.get_packet()->pts << "\tdts : " << pkt.get_packet()->dts;
    }
}

TEST(demuxer_test, demuxer_get_audio_pkt)
{
    demuxer::general_demuxer gd1(VIDEO_PATH);
    auto& video_stream = gd1.get_streams()[1];
    for (int cnt = 1;; ++cnt)
    {
        auto pkt = video_stream->get_packet();
        if (!pkt)
        {
            break;
        }
        LOG(INFO) << cnt << "\tpts : " << pkt.get_packet()->pts << "\tdts : " << pkt.get_packet()->dts;
    }
    auto& video_stream2 = gd1.get_streams()[2];
    for (int cnt = 1;; ++cnt)
    {
        auto pkt = video_stream2->get_packet();
        if (!pkt)
        {
            break;
        }
        LOG(INFO) << cnt << "\tpts : " << pkt.get_packet()->pts << "\tdts : " << pkt.get_packet()->dts;
    }
}
